﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;
using DevExpress.Web.ASPxEditors;

public partial class MemberInfo_MemberJnr : Frame.Pages.ActionInfomationEditBasePage
{
    //protected void Page_Load(object sender, EventArgs e)
    //{

    //}
    protected override string ActionID
    {
        get { return "6005"; }
    }

    protected override string UserFunctions
    {
        get
        {
            if (CMSUser.Current.IsLogin)
            {
                if (CMSUser.Current.IsAdmin)
                {
                    return "IUDQ";
                }
                else
                {
                    return CMSUser.GetFunction(ActionID) != null ? CMSUser.GetFunction(ActionID).op : "";
                }
            }
            else
            {
                return "";
            }
        }
    }

    protected override bool IsShowSpecialFunctions
    {
        get
        {
            if (CMSUser.Current.IsLogin)
            {
                if (CMSUser.Current.IsAdmin)
                {
                    return true;
                }
                else
                {
                    return CMSUser.GetFunction(ActionID) != null ? (CMSUser.GetFunction(ActionID).op_s == "Y" ? true : false) : false;
                }
            }
            else
            {
                return false;
            }
        }
    }

    protected void gridView_CellEditorInitialize(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewEditorEventArgs e)
    {
        if (e.Column.FieldName == "hybm")
        {
            if (e.Value == null)
            {
                using (DataClassesDataContext lqdb = new DataClassesDataContext())
                {
                    //int number = lqdb.css_hydj.Count() + 1;
                    //(e.Editor as ASPxTextBox).Text = number.ToString();
                    if (Request.QueryString["id"] != null)
                    {
                        string hybm = Request.QueryString["id"].ToString();
                        (e.Editor as ASPxTextBox).Text = hybm;
                    }
                }
            }
        }
        if (e.Column.FieldName == "jnrlx")
        {
            e.Editor.Focus();
        }
        e.Editor.SetClientSideEventHandler("KeyPress", @"function(s,e){var key = event.keyCode;if( key==13){EnterAsTab();}}");
    }
    protected void gridView_RowInserting(object sender, DevExpress.Web.Data.ASPxDataInsertingEventArgs e)
    {
        if (e.NewValues["hybm"] != null)
        {
            string Hybm = e.NewValues["hybm"].ToString();
            using (DataClassesDataContext lqdb = new DataClassesDataContext())
            {
                var result = lqdb.css_hydj_jnr.FirstOrDefault(r => r.hybm == Hybm);
                if (result != null)
                {
                    throw new Exception("对不起，不能重复添加！");
                }
            }
        }
    }
}